<template>
	<!--附近设备-->
	<scroll-view class="page-content" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
		<view class="page-body">
			<template v-if="datalist && datalist.length > 0 ">
				<block v-for="(item,index) in datalist" :key="index">
					<view class="body-box" @click="tonearby">
						<view class="box-tit">{{i18n.nearby.shebei}}：{{item.value}}</view>
						<view class="icons-sel">{{item.statu===true?i18n.nearby.jihuo:''}}<text class="icon-tb icons icon-gengduo"></text>
						</view>
					</view>
				</block>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
			<w-popup :show="showtip" :type="type1" @change="change1" :maskClick="false">
				<view class="w-tip">
					<view class="w-box">
						<view class="w-top">{{i18n.popup.tips}}</view>
						<view class="w-txt">{{i18n.popup.txt}}</view>
					</view>
					<view class="w-but">
						<view class="w-cancel" @click="cancel">{{i18n.popup.cancel}}</view>
						<view class="w-comfirm" @click="comfirm">{{i18n.popup.confirm}}</view>
					</view>
				</view>
			</w-popup>
		</view>
	</scroll-view>
</template>

<script>
	import wPopup from '@/components/w-popup/w-popup2.vue'
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import {
		getDeviceCodeLists,
		activateDevices,
	} from '@/common/api.js';
	import store from '@/store';
	import loadMore from '@/components/uni-load-more/load-more.vue';
	export default {
		components: {
			wPopup,loadMore
		},
		data() {
			return {
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				datalist: [{
						value: 'asdasdasd',
						statu: true,
					},
					{
						value: 'asdasdasd',
						statu: true,
					}
				],
				code_id: '',
				showtip: false, //是否显示弹窗1
				content1: '顶部弹 popup',
				type1: '', //弹窗显示方式
				formData:{
					page:1,
					limt:10
				}
			}
		},
		computed: {
			...mapGetters(["modelType", "pairStatu"]),
			i18n() {
				return this.$t('message');
			}
		},
		onShow() {
			// 导航栏多语言
			uni.setNavigationBarTitle({
				title: this.i18n.tabBar.nearby
			});
			this.getdata(this.formData);
		},
		onLoad(option) {
			if (option.code_id) {
				this.code_id = option.code_id;
			}
		},
		methods: {
			...mapActions("user", ["setModelType", "setPairStatu"]),
			//下拉加载
			loadmore() {
				console.log('下拉加载');
				let _self = this;
				_self.load_sta = true;
				_self.formData.page++;
				_self.getdata(_self.formData);
			},
			getdata(formData) {
				getDeviceCodeLists(formData).then(res => {
					console.log(333, res)
					if (res.code === 2000) {
						let datalist = [] //res.data;
						if (this.load_sta) {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = this.datalist.concat(datalist);
							} else {
								this.load_more1 = '加载中...';
									this.datalist = this.datalist.concat(datalist);
							}
						} else {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = datalist;
							} else {
								this.load_more1 = '加载中...';
									this.datalist = datalist;
							}
						}
					}
				})
			},
			comfirm(){
				this.showtip = false;
			},
			tonearby(code) {
				this.content1 = 'center'
				this.type1 = 'center';
				this.showtip = true;
				activateDevices().then(res =>{
					console.log(333,res)
					if(res.code === 2000){
						
					}
				})
			},
			change1(e) {
				if (!e.show) {
					this.showtip = false;
				}
			},
			//取消
			cancel(type) {
				this.showtip = false;
			},
		}
	}
</script>

<style lang="scss">
	.weixuanzhong {
		width: 36rpx;
		height: 36rpx;
		background: #393939;
		border: 1px solid #646464;
		border-radius: 50%;
	}
	.det-con-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
		color: #999;
		font-size: 24rpx;
	}
	.page-content {
		width: 100vw;
		height: 100%;
		background: $uni-bg-color;
		color: $font-color-w;
		.page-body{
			padding: $page-row-spacing;
			height: 100%;
		}
	}

	.body-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		background: $uni-bg-box-color;
		box-shadow: 0rpx 2rpx 9rpx 0rpx rgba(0, 0, 0, 0.44);
		border-radius: 20rpx;
		margin-bottom: 30rpx;
		padding: 30rpx 40rpx;
		color: #FFFFFF;

		.box-tit {
			display: flex;
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
		}

		.icons-sel {
			font-size: 28rpx;
			font-weight: 400;
			color: #D50000;

			.icon-tb {
				color: $font-color-w;
				margin-left: 20rpx;
			}
		}
	}

	/* 提示窗口 */
	.w-tip {
		display: flex;
		flex-direction: column;
		width: 90vw;
		min-height: 147rpx;
		border-radius: 10rpx;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		margin: 30rpx auto 0;
		overflow: hidden;

		.w-box {
			display: flex;
			flex-direction: column;
			padding: 30rpx 54rpx;
			

			.w-top {
				font-size: 36rpx;
				font-weight: bold;
				text-align: center;
				line-height: 63rpx;
				color: #393939
			}

			.w-txt {
				font-size: 32rpx;
				font-weight: 400;
				line-height: 56rpx;
				color: #393939;
			}
		}


		.w-but {
			display: flex;
			text-align: center;
			height: 100rpx;
			.w-cancel{
				flex: 1;
				font-size: 32rpx;
				font-weight: 400;
				line-height: 100rpx;
				color: #393939;
				background: #E9E9E9;
			}
			.w-comfirm{
				flex: 1;
				font-size: 32rpx;
				font-weight: 400;
				line-height: 100rpx;
				color: #FFFFFF;
				background: #D40000;
			}
		}
	}
</style>
